const eventBus = {};

export default {
    $on(eventName, handler){
        if(!eventBus[eventName]){
            eventBus[eventName] = new Set();
        }
        eventBus[eventName].add(handler);
    },
    $off(eventName, handler){
        if(!eventBus[eventName]){
            return;
        }
        eventBus[eventName].delete(handler);
    },
    $emit(eventName, ...args){
        if(!eventBus[eventName]){
            return;
        }
        for (const handler of eventBus[eventName]) {
            handler(...args);
        }
    }
}
